package com.ccz.demo.design.tertium.mybatisdemo.client;

import com.alibaba.fastjson.JSON;
import com.ccz.demo.design.tertium.mybatisdemo.Resources;
import com.ccz.demo.design.tertium.mybatisdemo.SqlSession;
import com.ccz.demo.design.tertium.mybatisdemo.SqlSessionFactory;
import com.ccz.demo.design.tertium.mybatisdemo.SqlSessionFactoryBuilder;
import com.ccz.demo.design.tertium.mybatisdemo.po.User;
import lombok.extern.slf4j.Slf4j;

import java.io.Reader;

@Slf4j
public class TestClient {
    public static void main(String[] args) {
        String resource = "mybatis-config-datasource.xml";
        Reader reader;
        try {
            reader = Resources.getResourceAsReader(resource);
            SqlSessionFactory sqlMapper = new SqlSessionFactoryBuilder().build(reader);

            SqlSession session = sqlMapper.openSession();
            try {
                User user = session.selectOne("com.ccz.demo.design.tertium.mybatisdemo.dao.IUserDao.queryUserInfoById", 1L);
                log.info("测试结果：{}", JSON.toJSONString(user));
            } finally {
                session.close();
                reader.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
